﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/MainContent.Master"
    Inherits="System.Web.Mvc.ViewPage<Guid>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    权限管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="fullBox">
<% using (Html.BeginForm())
       {%>
    <% IEnumerable<MShop.Core.Domain.Menu> menus = ViewData.Eval("menus") as IEnumerable<MShop.Core.Domain.Menu>; %>
  <div class="tabListBoxHead">
    <div style="float: left; padding-top: 3px;">                 
                当前角色：<%=this.Select("RoleId").Options(ViewData.Eval("roles") as IList<SelectListItem>).Attr("onchange", "go2Url();")%>
    </div>
    <div style="float: right;">
              <input type="submit" value="保存" class="btn" />
    <input type="button" value="返回" class="btn" onclick="location.href='/admin/roles/index';" /> 
    </div>
  </div>
    
    <div>
        
    </div>
	<div class="tabListBox">
    <table id="ETList" cellpadding="0" cellspacing="0">
	<thead>
        <tr>
            <th>
                菜单
            </th>
            <th>
                当前权限
            </th>
            <th>
                设定权限
            </th>
        </tr>
		</thead>
		<tbody>
        <% foreach (var item in menus)
           { %>
        <tr>
            <td>
                <%:item.Name%><%=Html.Hidden("MenuId", item.Id)%>
            </td>
            <td>
                <% var powers = item.Powers.FirstOrDefault(x => x.RoleId == Model);%>
                <%= powers != null ? powers.RightsString : "没有设定权限，请设定"%>
            </td>
            <td>
                <% 
                    var rights = typeof(MShop.Core.Domain.RightFlags).ConvertListItem();
                    if (powers != null)
                    {
                        rights = Html.ExamineRightFlags(rights, (MShop.Core.Domain.RightFlags)powers.Rights);
                    }                      
                %>
                <%=this.CheckBoxList("Rights" + item.Id).Options(rights).Id("Rights_" + item.Id)%>
            </td>
        </tr>
        <% } %>
		</tbody>
    </table>
	</div>
	
    <%} %>
</div>
    
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphMeta" runat="server">
    <script type="text/javascript">
        var go2Url = function () {
            location.href = '/admin/Powers/index?roleid=' + $("#RoleId").val() + '';
        }
    </script>
	<script type="text/javascript">
        $(document).ready(function () {
            var windowWidth = $("#fullBox").width();
            var windowHeight = $("#fullBox").height() - 30;
            $('.tabListBox').css({ 'width': windowWidth + 'px', 'height': windowHeight + 'px' });
            $(window).resize(function () {
                var windowWidth = $("#fullBox").width();
                var windowHeight = $("#fullBox").height() - 30;
                $('.tabListBox').css({ 'width': windowWidth + 'px', 'height': windowHeight + 'px' });
            });
            $('.tabListBox').fixedHeaderTable({ footer: false, cloneHeaderToFooter: false, autoResize: true, fixCol1: true });

            $('.tabListBox').find("tbody").find("tr").each(function (i) {
                if (i % 2 == 1) {
                    $(this).find("td").addClass("tr1");
                }
            });
            $('.tabListBox').find("tbody").find("tr").mouseover(function (i) {
                $(this).find("td").addClass("tr0");
            });
            $('.tabListBox').find("tbody").find("tr").mouseout(function (i) {
                $(this).find("td").removeClass("tr0");
            });

        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="cphFooter" runat="server">
</asp:Content>
